tweaking the way the dropdown opens to fix links not working
authorJake Goldsborough <rjgoldsborough@gmail.com>
Wed, 5 Oct 2016 23:40:10 +0000 (16:40 -0700)
committerJake Goldsborough <rjgoldsborough@gmail.com>
Thu, 6 Oct 2016 00:20:35 +0000 (17:20 -0700)
src/doc/javascripts/all.js

index 2694e8fc60ba83704cec7a4d9fd94344c437f557..d2124a9528f4ab5dd61d72563d27b225b0ced1c6 100644 (file)
@@ -19,18 +19,23 @@ $(function() {
         pres[i].className += ' language-rust';
     }
 
+    // Toggles docs menu
     $('button.dropdown, a.dropdown').click(function(el, e) {
-        $(this).toggleClass('active');
-        $(this).siblings('ul').toggleClass('open');
+        $(this).toggleClass('active').siblings('ul').toggleClass('open');
 
-        if ($(this).hasClass('active')) {
-            $(document).on('mousedown.useroptions', function() {
-                setTimeout(function() {
-                    $('button.dropdown, a.dropdown').removeClass('active');
-                    $('button.dropdown + ul').removeClass('open');
-                }, 150);
-                $(document).off('mousedown.useroptions');
-            });
+        return false;
+    });
+
+    // A click in the page anywhere but in the menu will turn the menu off
+    $(document).on('click', function(e) {
+        // Checks to make sure the click did not come from inside dropdown menu
+        // if it doesn't we close the menu
+        // else, we do nothing and just follow the link
+        if (!$(e.target).closest('ul.dropdown').length) {
+            var toggles = $('button.dropdown.active, a.dropdown.active');
+            toggles.toggleClass('active').siblings('ul').toggleClass('open');
+
+            return false;
         }
     });
 });